package com.zto.sch.beanfactoryprocessor;

import com.zto.sch.dao.CardDao;
import com.zto.sch.invoke.MyFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @program: javatest
 * @description:
 * @author: sch
 * @create: 2020-09-15 22:06
 **/
    public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        //扫描包：略
        //遍历包下面的类获取对象
        //创建bd,
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CardDao.class);
        //把bd放入map
        GenericBeanDefinition beanDefinition = (GenericBeanDefinition) builder.getBeanDefinition();
        beanDefinition.getConstructorArgumentValues().addGenericArgumentValue("com.zto.sch.dao.CardDao");
        beanDefinition.setBeanClass(MyFactoryBean.class);

        registry.registerBeanDefinition("cardDao", beanDefinition);
    }
}
